#ifndef __OPERATIONS__
#define __OPERATIONS__


#include <stdint.h>
#include "st.h"


#ifdef __cplusplus
extern "C" {
#endif

int op_chunk_create(st_netfd_t stfd, void* arg);
int op_chunk_close_fd(st_netfd_t stfd, void* arg);
int op_chunk_list(st_netfd_t stfd, void* arg);
int op_chunk_read(st_netfd_t stfd, void* arg);
int op_chunk_read3(st_netfd_t stfd, void* arg);
int op_chunk_read4(st_netfd_t stfd, void* arg);
int op_chunk_write(st_netfd_t stfd, void* arg);
int op_chunk_write3(st_netfd_t stfd, void* arg);
int op_chunk_write4(st_netfd_t stfd, void* arg);
int op_chunk_write_replicate(st_netfd_t stfd, void* arg);
int op_chunk_write_replicate2(st_netfd_t stfd, void* arg);
int op_chunk_write_replicate3(st_netfd_t stfd, void* arg);
int op_chunk_write_replicate4(st_netfd_t stfd, void* arg);
int op_chunk_write_replicate4_1(st_netfd_t stfd, void* arg);
int op_chunk_write_replicate4all(st_netfd_t stfd, void* arg);
int op_chunk_create_write_replicate(st_netfd_t stfd, void* arg);
int op_chunk_get_version(st_netfd_t stfd, void* arg);
int op_chunk_flush(st_netfd_t stfd, void* arg);
int op_chunk_delete(st_netfd_t stfd, void* arg);
int op_chunk_undelete(st_netfd_t stfd, void* arg);
int op_chunk_checksum(st_netfd_t stfd, void* arg);
int op_chunk_clone(st_netfd_t stfd, void* arg);
int op_chunk_breed(st_netfd_t stfd, void* arg);
int op_chunk_sync_data(st_netfd_t stfd, void *arg);
int op_chunk_suspend_write(st_netfd_t stfd, void* arg);
int op_chunk_notify_new_replica(st_netfd_t stfd, void* arg);
int op_chunk_start_incubation(st_netfd_t stfd, void* arg);
int op_chunk_incubation_done(st_netfd_t stfd, void* arg);
int op_chunk_server_terminate(st_netfd_t stfd, void* arg);
int op_chunk_server_ping(st_netfd_t stfd, void* arg);
int op_chunk_rename(st_netfd_t stfd, void* arg);
int op_chunk_update(st_netfd_t stfd, void* arg);
int op_chunk_get_journal(st_netfd_t stfd, void *arg);
int op_chunk_get_info(st_netfd_t stfd, void* arg);
int op_chunk_fix(st_netfd_t stfd, void* arg);
int op_chunk_server_restart(st_netfd_t stfd, void *arg);
int op_chunk_check_suspend(st_netfd_t stfd, void* arg);
int op_chunk_flush_journal(st_netfd_t stfd, void* arg);
int op_chunk_get_big_journal_meta(st_netfd_t stfd, void* arg);
//int op_chunk_fake(st_netfd_t stfd, void* arg);

void chunk_operations_init();
void chunk_operations_fini();

int write_back_journal_cb(uint32_t volumeid, uint32_t index, void* buf, off_t offset, size_t towrite,
							uint64_t version, bool inc_version, bool just_write_data);

int checksum_sendfile(st_netfd_t out_fd, struct Chunk* chunk,
		off_t offset, size_t count);
int send_mmaped_buf(st_netfd_t out_fd, void* buf, size_t count);
int local_chunk_write(struct Chunk* chunk, void* buf, uint64_t offset, uint64_t towrite, bool updatechecksum, time_t client_time);

int ec_or_big_journal_sendfile(st_netfd_t out_fd, struct Chunk* chunk,
							   off_t offset, size_t count)
{
	throw "not implemented";
	return -1;
}

int op_chunk_fake(st_netfd_t stfd, void* arg)
{
	throw "Not Implemented";
	return -1;
}

#ifdef __cplusplus
}
#endif

//#include "operations-ec.h"
//#include "operations-ec-journal.h"

#endif
